#FROM ccr.ccs.tencentyun.com/douhua/golang:1.22.8-alpine as GO_BUILD
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/library/golang:1.23.4-alpine as GO_BUILD
LABEL maintainer="suihongcang.cn"
WORKDIR /build

ENV GOPROXY=https://goproxy.cn

# 复制项目中的 go.mod 和 go.sum文件并下载依赖信息
COPY . .
RUN go mod tidy
RUN go mod download
RUN go build -o app short-link/cmd

FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/library/alpine:latest
LABEL maintainer="suihongcang.cn"
WORKDIR /opt/short-link
COPY resources /opt/short-link/resources
COPY --from=GO_BUILD /build/app /opt/short-link/app
RUN echo "#aliyun" > /etc/apk/repositories
RUN echo "https://mirrors.aliyun.com/alpine/v3.12/main/" >> /etc/apk/repositories
RUN echo "https://mirrors.aliyun.com/alpine/v3.12/community/" >> /etc/apk/repositories
RUN apk update
RUN apk add --no-cache ca-certificates tzdata curl
RUN mkdir logs
ENV TZ=Asia/Shanghai
EXPOSE 8080

ENTRYPOINT [ "/opt/short-link/app" ]